package cn.tlb.gl.game.rebuild2;

import java.nio.FloatBuffer;

/**
 * Created by 汤林冰 on 2016/1/13 15:09.
 */
public class Cuboid {

    public float ox;
    public float oy;
    public float oz;
    public float length;
    public float width;
    public float height;
    //faces vertex buffer
    public FloatBuffer top;
    public FloatBuffer bottom;
    public FloatBuffer left;
    public FloatBuffer right;
    public FloatBuffer front;
    public FloatBuffer back;

    /**
     * @param ox
     * @param oy  (ox, oy, oz)立方体几何中心坐标
     * @param length
     * @param width
     * @param height    length, width, height 立方体长宽高
     *
     */
    public Cuboid(float ox, float oy, float oz, float length, float width, float height) {
        this.ox = ox;
        this.oy = oy;
        this.oz = oz;
        this.length = length;
        this.width = width;
        this.height = height;
        genFaces(ox, oy, oz, length, width, height);
    }

    public Cuboid(float length, float width, float height) {
        this(0, 0, 0, length, width, height);
    }

    public Cuboid() {
        this(0, 0, 0, 0, 0, 0);
    }

    private void genFaces(float center_x, float center_y, float center_z, float length, float width, float height) {

        top = cn.tlb.gl.game.rebuild2.BufferUtil.wrap(new float[]{
                center_x - length, center_y + height, center_z - width,
                center_x - length, center_y + height, center_z + width,
                center_x + length, center_y + height, center_z - width,
                center_x - length, center_y + height, center_z + width,
                center_x + length, center_y + height, center_z - width,
                center_x + length, center_y + height, center_z + width,
        });

        bottom = cn.tlb.gl.game.rebuild.BufferUtil.wrap(new float[]{
                center_x - length, center_y - height, center_z - width,
                center_x - length, center_y - height, center_z + width,
                center_x + length, center_y - height, center_z - width,
                center_x - length, center_y - height, center_z + width,
                center_x + length, center_y - height, center_z - width,
                center_x + length, center_y - height, center_z + width,
        });

        left = cn.tlb.gl.game.rebuild.BufferUtil.wrap(new float[]{
                center_x - length, center_y + height, center_z - width,
                center_x - length, center_y - height, center_z - width,
                center_x - length, center_y + height, center_z + width,
                center_x - length, center_y - height, center_z - width,
                center_x - length, center_y + height, center_z + width,
                center_x - length, center_y - height, center_z + width,
        });

        right = cn.tlb.gl.game.rebuild.BufferUtil.wrap(new float[]{
                center_x + length, center_y + height, center_z + width,
                center_x + length, center_y - height, center_z + width,
                center_x + length, center_y + height, center_z - width,
                center_x + length, center_y - height, center_z + width,
                center_x + length, center_y + height, center_z - width,
                center_x + length, center_y - height, center_z - width,
        });

        front = cn.tlb.gl.game.rebuild.BufferUtil.wrap(new float[]{
                center_x - length, center_y + height, center_z + width,
                center_x - length, center_y - height, center_z + width,
                center_x + length, center_y + height, center_z + width,
                center_x - length, center_y - height, center_z + width,
                center_x + length, center_y + height, center_z + width,
                center_x + length, center_y - height, center_z + width,
        });

        back = BufferUtil.wrap(new float[]{
                center_x - length, center_y + height, center_z - width,
                center_x - length, center_y - height, center_z - width,
                center_x + length, center_y + height, center_z - width,
                center_x - length, center_y - height, center_z - width,
                center_x + length, center_y + height, center_z - width,
                center_x + length, center_y - height, center_z - width,
        });
    }
}
